/***************************************************************************
 创建者: 华磊
 开始时间: 2019.1.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef CU1SENSORADAPTER_H
#define CU1SENSORADAPTER_H
#include <QObject>
#include <QTimer>
#include "../HmiGsoapQt/gSoapFoundation/soapStub.h"
#include "GeneralDefine.h"

class QTcpSocket;
class QTimer;
class Cu1PositionCalculate;

struct SensorRawData
{
    bool issuc;
    int errcode;
    double d1;
    double d2;
    double offsetx;
};

class Cu1SensorAdapter : public QObject
{
    Q_OBJECT
public:
    explicit Cu1SensorAdapter(QString configFileIn,QObject *parent = nullptr);

public:
    bool isInitialOk();
    bool isSocketOkStatus();
    bool isUseThisModule();
    int getVehiclePosition(PositionInfo &positionOut);
    int getRawData(int &requestCountOut,double &l1Out,double &l2Out,double &imageOffsetOut
                                                    ,bool &isSucessOut,int &errorCodeOut);

signals:

public slots:
    void timeOut_slot();

private:
    int connectSensorServer(QString ip,int port);
    int initialConfigFile(QString configFileName);
    int sendGetLaserInfoCommand();
    int sendGetImageInfoCommand();
    int sendGetAllInfoCommand();
    int processReceiveBuff(VehiclePosition &posOut);
    int process_manual_allSensorData(QJsonObject &redeiveJsonObjIn, SensorRawData &dataOut);
private:
    int laserSensorDirection;//1表示正向，－１表示负向。
    bool isUseCu1Sensor;
    QString sensorServerIp;
    int sensorServerPort;
    double distanceOfTwoLaser;//两个单点激光头的安装间距。
    double distanceOfLaserAndVehicleCenter;//激光头测量中心到车体原点的距离
    double distanceOffsetOfCamera;//摄像头安装位置与激光头位置的偏差，往前为负
    double ratioOfPix;//像素偏差和距离偏差的比值。负数调节方向
    bool isInitialOkStatus;
    bool isConnectedStatus;

    QTcpSocket *clientSocket;
//    bool isSocketOk;
    QTimer* timer;
//    int laserRequestCount;
    int imageRequestCount;
    int maxRequestLimit;
    Cu1PositionCalculate *posCalculate;

    double laser1Data;//m
    bool isLaser1DataOk;
    bool isLaser2DataOk;
    double laser2Data;//m
    double imageOffsetData;//m
    bool isSensorSucess;
    int sensorErrorCode;
    double laserSensorMaxRange;

    VehiclePosition positionFeedback;
};

#endif // CU1SENSORADAPTER_H
